<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div v-if="isDeleteShow">
        <span @click="clear">全部删除</span>
        &nbsp;&nbsp;
        <span @click="isDeleteShow = false">完成</span>
      </div>
      <van-icon v-else name="delete" @click="isDeleteShow = true" />
    </van-cell>
    <van-cell v-for="(v,i) in listAll" :key="i">
      <span>{{v}}</span>
      <van-icon v-show="isDeleteShow" name="close" @click="clearOne(i)" />
    </van-cell>
  </div>
</template>

<script>
import { removeItem, setItem, getItem } from '@/utils/storage'
export default {
  name: 'SearchHistory',
  props: {},
  created () {
    this.listAll = getItem('lists')
    console.log(this.listAll)
  },
  data () {
    return {
      isDeleteShow: false,
      listAll: []
    }
  },
  methods: {
    onSearchItemClick (item, index) {
      if (this.isDeleteShow) {

      } else {
        // 非删除状态，直接进入搜索
        this.$emit('search', item)
      }
    },
    clear () {
      removeItem('lists')
      this.listAll = []
      this.$emit('clearAll1')
    },
    clearOne (i) {
      this.listAll.splice(i, 1)
      this.$emit('clearOne1', i)
      setItem('lists', this.listAll)
    }
  }
}
</script>

<style scoped lang="less">
</style>
